package com.mycjj.android.activity;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.ProjectDataManage;
import com.mycjj.android.R;
import com.mycjj.android.adapter.AdviserAdapter;
import com.mycjj.android.adapter.TAdapter;
import com.mycjj.android.bean.AdvisersBaseBean;
import com.mycjj.android.bean.Adviser;
import com.mycjj.android.bean.BaseBean;
import com.mycjj.android.http.ProjectHttpRequestImpl;
import com.mycjj.android.http.ProjectHttpRequestInterface;
import com.mycjj.android.util.Preferences;

public class Point_SelectAdviserActivity extends BaseActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_point_selectadviser);
		mActManager.pushActivity(YUYUE_KEY, this);
		initHeader();
		init();
	}

	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		mHeaderRightButton.setVisibility(View.GONE);
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("选择顾问");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mActManager.popActivity(YUYUE_KEY,Point_SelectAdviserActivity.this);
			}
		});
	}

	private ListView lv_adviser;
	private AdviserAdapter adviserAdapter;
	private TextView mTv_store_name;
	private void init() {
		
		mTv_store_name = (TextView)findViewById(R.id.tv_store_name);
		lv_adviser = (ListView) findViewById(R.id.lv_adviser);
		adviserAdapter = new AdviserAdapter(this,"咨询");
		lv_adviser.setAdapter(adviserAdapter);
		initData();

		lv_adviser.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Adviser adviser = list.get(position);
				Intent intent = new Intent(Point_SelectAdviserActivity.this,Point_CommentActivity.class);
				intent.putExtra("data", adviser);
				intent.putExtra("type", 0);
				startActivity(intent);
			}
		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		mTv_store_name.setText(Preferences.getSharedPreferences(mApp, "storeName", "浙江奥同汽车有限公司"));
	}
	
	

	private List<Adviser> list;

	private void initData() {
		request = new ProjectHttpRequestImpl(this, true);
		RequestParams params = new RequestParams();
		String store_id = Preferences.getSharedPreferences(this, "storeId", "");
		String token = Preferences.getSharedPreferences(this, "user_token", "");
		params.put("store_id", store_id);
		params.put("limit", "100");
		params.put("offset", "0");
		params.put("client_id", ProjectHttpRequestInterface.client_id_key);
		params.put("token", token);

		request.requestStoreGetAdvisersWithDoneHandler("", params,
				new AsyncHttpResponseHandler() {
					@Override
					public void onSuccess(String content) {
						AdvisersBaseBean baseBean = ProjectDataManage
								.getInstance().getAdvisersBaseBean();
						if (baseBean != null) {
							if (baseBean.getCode() == 200) {
								if (baseBean.getData() != null) {
									list = baseBean.getData().getList();
									adviserAdapter.setList(list);
								} else {
									Toast.makeText(Point_SelectAdviserActivity.this,
											"顾问列表为空!", Toast.LENGTH_SHORT)
											.show();
								}

							}
						}

					}
				});
	}

	
}
